﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace _10_06Prism模块化ModuleC.ViewModels
{
	public class ViewCViewModel:BindableBase,INavigationAware,IConfirmNavigationRequest
	{
		//BindaleBase用来通知的
		//在主页面的MainViewModel上传入了参数，需要用容器去接收，所以用INavigationAware接口
		//IConfirmNavigationRequest 也继承INavigationAware,是否允许切换其他的模块
		public ViewCViewModel() 
		{

		}	



		private string title;
		public string Title { get { return title; } set { title = value; RaisePropertyChanged(); } }

		//INavigationAware的三个方法
		public void OnNavigatedTo(NavigationContext navigationContext)
		{
			//这个方法用来接收参数的
			if (navigationContext.Parameters.ContainsKey("Title"))
			{
				Title = navigationContext.Parameters.GetValue<string>("Title");
			}
		}

		/// <summary>
		/// 每次重新导航的时候，是否重用原来实例
		/// </summary>
		/// <param name="navigationContext"></param>
		/// <returns></returns>
		public bool IsNavigationTarget(NavigationContext navigationContext)
		{
			//返回true是用原来的实例
			return true;
		}

		//拦截导航请求的，在切换其他模块的时候被触发的，差不多是在离开的时候触发的

		public void OnNavigatedFrom(NavigationContext navigationContext)
		{
			
		}

		public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
		{
			//bool result = true;
			//if (MessageBox.Show("确认导航", "温馨提示", MessageBoxButton.YesNo) == MessageBoxResult.No)
			//{
			//	result= false;
			//}
			//continuationCallback(result);
		}
	}
}
